home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Application.c
-
- Contains: A Sample application for High-level text conversion
-
- Version: Technology: System 8
- Release: Daruma Developer Release 1
-
- Copyright: 1998 by Apple Computer, Inc., all rights reserved
-
- Contact: daruma@apple.com
-
- */
-
-
- #include "HighLevelTextConvert.h"
- #include "Application.h"
-
- #include <Dialogs.h>
-
-
- //========================================================================================
- // Prototypes for static functions
- //========================================================================================
- static void ToolboxInitialize( void );
- static void DoMainDialog( void );
- static Handle GetDialogItemHandle( DialogRef dialog, short itemNo );
- static void ShowErrorAlert ( OSStatus error );
- static void ChangeDefautItem( DialogRef dialog, SInt16 newDefaultItem );
-
-
- /* =======================================================================================
- main
- ======================================================================================= */
- void main ( void )
- {
- ToolboxInitialize();
- DoMainDialog();
- }
-
-
- /* =======================================================================================
- ToolboxInitialize
- ======================================================================================= */
- static void ToolboxInitialize( void )
- {
- InitGraf( (Ptr)&qd.thePort);
- InitFonts();
- FlushEvents( everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil);
- InitCursor();
- }
-
-
- /* =======================================================================================
- DoMainDialog
- ======================================================================================= */
- static void DoMainDialog( void )
- {
- OSStatus err;
- DialogRef dialog;
- GrafPtr savePort;
- short itemHit = 0;
- Str255 srcStr, dstStr;
- ByteCount actualLength;
-
- GetPort( &savePort);
-
- dialog = GetNewDialog( kMainDialogResID, NULL, (WindowRef)-1L);
- if ( dialog == NULL) goto errExit;
-
- SetPort( dialog);
-
- ChangeDefautItem( dialog, kConvToKanjiBtnItem);
-
- while ( itemHit != kQuitBtnItem)
- {
- ModalDialog( NULL, &itemHit);
-
- if ( itemHit == kConvToKanjiBtnItem)
- {
- GetDialogItemText( GetDialogItemHandle( dialog, kYomiEditTextItem), srcStr);
-
- err = LaConvertPascalString( kConvertKanaToKanji, srcStr, &actualLength, dstStr);
- if ( err != noErr) goto errExit;
-
- SetDialogItemText( GetDialogItemHandle( dialog, kKanjiEditTextItem), dstStr);
- }
- else if ( itemHit == kConvToYomiBtnItem)
- {
- GetDialogItemText( GetDialogItemHandle( dialog, kKanjiEditTextItem), srcStr);
-
- err = LaConvertPascalString( kConvertKanjiToKana, srcStr, &actualLength, dstStr);
- if ( err != noErr) goto errExit;
-
- SetDialogItemText( GetDialogItemHandle( dialog, kYomiEditTextItem), dstStr);
- }
- else if ( itemHit == kYomiEditTextItem)
- {
- ChangeDefautItem( dialog, kConvToKanjiBtnItem);
- }
- else if ( itemHit == kKanjiEditTextItem)
- {
- ChangeDefautItem( dialog, kConvToYomiBtnItem);
- }
- }
-
- errExit:;
- SetPort( savePort);
-
- if ( dialog != NULL)
- DisposeDialog( dialog);
- else
- ShowErrorAlert( err);
-
- LaFinalizeConvert();
- }
-
-
- /* =======================================================================================
- ShowErrorAlert
- ======================================================================================= */
- static void ShowErrorAlert ( OSStatus error )
- {
- Str31 errNumStr;
-
- if ( error == noErr) return;
-
- NumToString( error, errNumStr);
- ParamText( errNumStr, "\p", "\p", "\p");
-
- Alert( kErrorAlertResID, NULL);
- }
-
-
- /* =======================================================================================
- GetDialogItemHandle
- ======================================================================================= */
- static Handle GetDialogItemHandle( DialogRef dialog, short itemNo )
- {
- short itemType;
- Handle itemHandle;
- Rect box;
-
- GetDialogItem( dialog, itemNo, &itemType, &itemHandle, &box);
- return itemHandle;
- }
-
-
- /* =======================================================================================
- ChangeDefautItem
- ======================================================================================= */
- static void ChangeDefautItem( DialogRef dialog, SInt16 newDefaultItem )
- {
- GrafPtr savePort;
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- SInt16 curDefaultItem = GetDialogDefaultItem( dialog);
- RgnHandle targetRgn, tempRgn;
-
- if ( newDefaultItem != curDefaultItem)
- {
- GetPort( &savePort);
- SetPort( dialog);
-
- SetDialogDefaultItem( dialog, newDefaultItem);
-
- targetRgn = NewRgn();
- tempRgn = NewRgn();
-
- GetDialogItem( dialog, curDefaultItem, &itemType, &itemHandle, &itemRect);
- RectRgn( tempRgn, &itemRect);
- InsetRect( &itemRect, -6, -6);
- RectRgn( targetRgn, &itemRect);
- DiffRgn( targetRgn, tempRgn, targetRgn);
- EraseRgn( targetRgn);
-
- GetDialogItem( dialog, newDefaultItem, &itemType, &itemHandle, &itemRect);
- RectRgn( tempRgn, &itemRect);
- InsetRect( &itemRect, -6, -6);
- RectRgn( targetRgn, &itemRect);
- DiffRgn( targetRgn, tempRgn, targetRgn);
- InvalRgn( targetRgn);
-
- DisposeRgn( targetRgn);
- DisposeRgn( tempRgn);
-
- SetPort( savePort);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-